import RPi.GPIO as GPIO

# 按物理位置找接口
import time

GPIO.setmode(GPIO.BOARD)

# 7号口负责输出电压
GPIO.setup(7, GPIO.OUT)


# 按GPIO号找
# GPIO.setmode(GPIO.BCM)
def led_flash(max_times):
    """
    控制led灯闪烁
    :param max_times: 最大的闪烁次数
    :return:
    """
    i = 0
    while i < max_times:
        GPIO.output(7, GPIO.HIGH)
        time.sleep(0.5)
        GPIO.output(7, GPIO.LOW)
        time.sleep(0.5)
        i = i + 1


def breath_flash():
    """
    呼吸灯
    :return:
    """
    try:
        p = GPIO.PWM(7, 50)
        p.start(0)
        i = 0
        while i < 10:
            for dc in range(0, 101, 5):
                p.ChangeDutyCycle(dc)
                time.sleep(0.1)

            for dc in range(100, -1, 5):
                p.ChangeDutyCycle(dc)
                time.sleep(0.1)
            i = i + 1
        p.stop()
    except KeyboardInterrupt:
        pass


breath_flash()
GPIO.cleanup()
